package com.fr.work.job;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.commons.collections.CollectionUtils;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

public class MonitorJob {
	
	public static final int MAX_WAITING_TIME = 5;

	private static int AVAILABLEPROCESSORS = Runtime.getRuntime()
			.availableProcessors();

	public static final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
			AVAILABLEPROCESSORS * 50, AVAILABLEPROCESSORS * 80, 0L,
			TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(
					AVAILABLEPROCESSORS * 2000), new ThreadFactoryBuilder()
					.setNameFormat("ESWrapper-pool-Thread-%d").build());
	public static void job() {
		if (ESWrapper.isMonitor) {
			if (CollectionUtils.isNotEmpty(ESWrapper.noQuerySet)) {
				synchronized (ESWrapper.noQuerySet) {
					for (String s : ESWrapper.noQuerySet) {
						System.out.println(s);
					}
					ESWrapper.noQuerySet.clear();
				}
			}
		}
	}

	public static void main(String[] args) {
//		for (int i = 0; i < 1000; i++) {
//			threadPoolExecutor.execute(new A(String.valueOf(i), String.valueOf(i)));
//		}
//		job();
//		for (int i = 0; i < 1000; i++) {
//			threadPoolExecutor.execute(new A(String.valueOf(i), String.valueOf(i)));
//		}
		ESWrapper.mothed("2", "2");
	}

	static class A implements Runnable {
		String a;
		String b;

		public A(String a, String b) {
			this.a = a;
			this.b = b;
		}

		@Override
		public void run() {
			ESWrapper.mothed(a, b);
		}

	}
}
